package com.zz.common.codeGenerator.controller;

import com.zz.common.base.dto.PageListResultDto;
import com.zz.common.base.dto.ResponseDTO;
import com.zz.common.base.dto.ResultDto;
import com.zz.common.codeGenerator.dto.GenFormSchemaDto;
import com.zz.common.codeGenerator.service.GenFormSchemaService;
import com.zz.common.constants.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 表单Schema配置 服务接口类
 *
 * @author zl
 * @since 2025-11-22 08:29:41
 */
@Api(tags = "表单Schema配置服务接口类")
@RestController
@RequestMapping("code-generator/v1.0/code-generator")
public class GenFormSchemaController {

    @Resource
    private GenFormSchemaService genFormSchemaService;

    @RequestMapping(value = "/query-with-page", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-分页查询", notes = "传入分页信息")
    public PageListResultDto<GenFormSchemaDto> queryWithPage(@RequestBody GenFormSchemaDto genFormSchemaDto) {
        PageListResultDto<GenFormSchemaDto> res;
        res = genFormSchemaService.queryWithPage(genFormSchemaDto, genFormSchemaDto.getQueryParam());
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }


    @RequestMapping(value = "/query-with-no-page", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-不分页查询", notes = "传入查询条件信息")
    public ResponseDTO<List<GenFormSchemaDto>> queryWithNoPage(@RequestBody GenFormSchemaDto genFormSchemaDto) {
        ResponseDTO<List<GenFormSchemaDto>> res = new ResponseDTO<>();
        res.setData(genFormSchemaService.queryWithNoPage(genFormSchemaDto));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "表单Schema配置-查询ById", notes = "传入id")
    public ResponseDTO<GenFormSchemaDto> queryById(@PathVariable("id") String id) {
        ResponseDTO<GenFormSchemaDto> res = new ResponseDTO<>();
        GenFormSchemaDto result = genFormSchemaService.queryById(id);
        res.setData(result);
        return res;
    }

    @RequestMapping(value = "/query-by-table-id/{tableId}", method = RequestMethod.GET)
    @ApiOperation(value = "表单Schema配置-查询ByTableId", notes = "传入tableId")
    public ResponseDTO<GenFormSchemaDto> queryByTableId(@PathVariable("tableId") String tableId) {
        ResponseDTO<GenFormSchemaDto> res = new ResponseDTO<>();
        GenFormSchemaDto result = genFormSchemaService.queryByTableId(tableId);
        res.setData(result);
        return res;
    }

    @RequestMapping(value = "/query-by-ids", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-查询ByIds", notes = "传入ids")
    public ResponseDTO<List<GenFormSchemaDto>> queryByIds(@RequestBody List<String> ids) {
        ResponseDTO<List<GenFormSchemaDto>> res = new ResponseDTO<>();
        res.setData(genFormSchemaService.queryByIds(ids));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-创建", notes = "创建")
    public ResultDto save(@RequestBody GenFormSchemaDto genFormSchemaDto) {
        ResultDto res = new ResultDto();
        genFormSchemaService.save(genFormSchemaDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save-batch", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-创建", notes = "创建")
    public ResultDto saveBatch(@RequestBody List<GenFormSchemaDto> genFormSchemaDtos) {
        ResultDto res = new ResultDto();
        genFormSchemaService.saveBatch(genFormSchemaDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-修改", notes = "修改")
    public ResultDto modify(@RequestBody GenFormSchemaDto genFormSchemaDto) {
        ResultDto res = new ResultDto();
        genFormSchemaService.modify(genFormSchemaDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify-batch", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-修改", notes = "修改")
    public ResultDto modifyBatch(@RequestBody List<GenFormSchemaDto> genFormSchemaDtos) {
        ResultDto res = new ResultDto();
        genFormSchemaService.modifyBatch(genFormSchemaDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "表单Schema配置-删除ById", notes = "传入id")
    public ResultDto delete(@PathVariable("id") String id) {
        ResultDto res = new ResultDto();
        genFormSchemaService.delete(id);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-batch", method = RequestMethod.POST)
    @ApiOperation(value = "表单Schema配置-批量删除", notes = "传入id")
    public ResultDto deleteBatch(@RequestBody List<String> ids) {
        ResultDto res = new ResultDto();
        genFormSchemaService.deleteBatch(ids);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

}